const Koa = require("koa");
const app = new Koa();
const router = require("./router"); //导入路由
const { koaBody } = require("koa-body"); //导入解析Post请求体中间件
const cors = require("@koa/cors"); //跨域中间件


app.use(cors());
app.use(koaBody());
app.use(router.routes()); //调用路由解析方法

//监听错误
app.on("error", (error, ctx) => {
  console.log("程序发生错误" + error);
  ctx.body = error;
});

//开启监听
app.listen(3000, () => {
   console.log('\x1b[32m%s\x1b[0m', 'server run in http://127.0.0.1:3000 Success!');
});
